<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Mixins</title>
  </head>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
  <body>
    <h1>Hello Mixins</h1>
    <hr />
    <div id="app">
      {{count}}
      <p><button @click="add">add</button></p>
    </div>
  </body>

  <script>
    addConsole = {
      // Vue的生命周期
      updated: function () {
        console.log(this.count)
      }
    }
    // 全局混入：最先执行
    Vue.mixin({
      updated: function () {
        console.log('全局混入' + this.count)
      }
    })

    var app = new Vue({
      el: '#app',
      data: {
        count: 1
      },
      methods: {
        add: function () {
          this.count++
        }
      },
      // 后执行
      updated: function () {
        console.log('我是原生的updated')
      },
      // 先执行
      mixins: [addConsole]
    })

  </script>
</html>
